class CoreController < ApplicationController
  
  include CoreHelper
  
  $login = "core/templates/login"
  
  #@menutype the idea is to pass the type of content in the login div and not check it in the _menu.html.erb. 
  #@menutype the method current_user_type is in the helper
  def index
 #   @users = params[:users] unless params[:users] == nil    
    
    #creates the super user at the beginning
    if User.find(:all).length == 0
      u = User.new
      u.name = 'Admin'
      u.email = 'super@lu.unisi.ch'
      u.privilege = 1
      u.password = '123456'
    
      u.save
    end

  #  @body = unless params[:body] != nil then "core/templates/body" else params[:body] end
  #  @menutype = unless session[:user_id] == nil then current_user_type(session[:user_id])  else "login" end
    @menutype = $login
    @user = User.find(session[:user_id]) unless session[:user_id] == nil
    if(@user != nil) then @menutype = current_user_type(@user) end
    
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @cores }
    end
  end
  
  #Just a simple login out function
  def logout
      session[:user_id] = nil
      redirect_to :action => "index"
  end
  
  #This is actually the logout
  def show
    session[:user_id] = nil
    redirect_to :action => "index"
  end
 
  
end
